import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { RecipeInfoEntity } from '../../entity/info';
import { RecipeInfoService } from '../../service/info';
import { RecipeCategoryEntity } from '../../entity/category';

/**
 * 菜谱信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: RecipeInfoEntity,
  service: RecipeInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['a.name'],
    fieldEq: ['a.categoryId', 'a.status'],
    addOrderBy: {
      createTime: 'DESC',
    },
    select: ['a.*', 'b.name AS categoryName'],
    join: [
      {
        entity: RecipeCategoryEntity,
        alias: 'b',
        condition: 'a.categoryId = b.id',
        type: 'leftJoin',
      },
    ],
  },
})
export class AdminRecipeInfoController extends BaseController {
  @Inject()
  recipeInfoService: RecipeInfoService;
}
